'''
Created on Oct 8, 2012

@author: thiagoponte
'''
def donuts(count):
    if count < 10:
        return 'Number of donuts: ' + str(count)
    else:
        return 'Number of donuts: many'

#spng    
def sub(s):
    if len(s) > 2:
        return s[0:2] + s[-2:] 
    else :
        return ''

# C. fix_start
# Given a string s, return a string
# where all occurences of its first char have
# been changed to '*', except do not change
# the first char itself.
# e.g. 'babble' yields 'ba**le'
# Assume that the string is length 1 or more.
# Hint: s.replace(stra, strb) returns a version of string s
# where all instances of stra have been replaced by strb.
def fix_start(s):
    return s[0]+s[1:].replace(s[0],'*')


# D. MixUp
# Given strings a and b, return a single string 
# with a and b separated
# by a space '<a> <b>', except swap the first 2 chars 
# of each string.
# e.g.
#   'mix', pod' -> 'pox mid'
#   'dog', 'dinner' -> 'dig donner'
# Assume a and b are length 2 or more.
def mix_up(a, b):
    return b[0] + b[1] + a[2:] + ' ' + a[0] + a[1] + b[2:]

# D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchanged.
# Return the resulting string.
def verbing(s):
    if len(s) >= 3:
        if s[-3:] == 'ing':
            return s + 'ly'
        else:
            return s + 'ing'
    else:
        return s
   

# E. not_bad
# Given a string, find the first appearance of the
# substring 'not' and 'bad'. If the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# Return the resulting string.
# So 'This dinner is not that bad!' yields:
# This dinner is good!
def not_bad(a):
    if a.find('bad') > a.find('not'):
        if a.find('bad')+3 == len(a) :
            return a[:a.find('not')] + 'good'
        else:
            return a[:a.find('not')] + 'good' + a[a.find('bad') + 3]
    else:
        return a

# F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 strings, a and b, return a string of the form
#  a-front + b-front + a-back + b-back
def front_back(a, b):
    if len(a) % 2 == 0:
        aFront = a[:len(a)/2]
        aBack =  a[len(a)/2:]
    else:
        aFront = a[:(len(a)/2) + 1]
        aBack =  a[(len(a)/2) + 1:]
    if len(b) % 2 == 0:
        bFront = b[:len(b)/2]
        bBack =  b[len(b)/2:]
    else:
        bFront = b[:(len(b)/2) + 1]
        bBack =  b[(len(b)/2) + 1:]
    return aFront + bFront+ aBack + bBack


def main():
    print front_back('abcd', 'xy')


# Standard boilerplate to call the main() function.
if __name__ == '__main__':
    main()